package com.xiaomi.servlet;

import com.google.gson.Gson;
import com.xiaomi.entity.Type;
import com.xiaomi.service.TypeService;
import com.xiaomi.service.impl.TypeServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * TODO
 *
 * @author jy
 * @date 2021/5/24
 */
@WebServlet(name = "TypeServlet", value = "/type")
public class TypeServlet extends BaseServlet {

    private final TypeService typeService = new TypeServiceImpl();

    /**
     * 查询出所有的类型 返回json字符串给head.jsp页面
     */
    protected String typeListToJson(HttpServletRequest req, HttpServletResponse resp){
        List<Type> list = typeService.typeListToJson();
        //转换json字符串
        Gson gson = new Gson();
        return gson.toJson(list);
    }

}
